<!--组织 -->
<!-- OrganizePageAddFromDialog -->
<template>
    <div class="app-container"
         v-loading.fullscreen.lock="allLoading"
         element-loading-text="拼命处理中,请耐心等待"
         element-loading-spinner="el-icon-loading"
         element-loading-background="rgba(0, 0, 0, 0.8)"
    >
        <el-dialog :close-on-click-modal="false" :title="mainDialogInfo.title" :visible.sync="showDialog" width="50%"  append-to-body @close="closeDialog">
            <el-form ref="form" :model="form" :rules="rules" label-width="120px">
                <el-row>
                    <el-col :span="24">
                        <el-form-item prop="orgName" label="组织">
                            <el-input   v-model="form.orgName" placeholder="请输入" />
                        </el-form-item>
                        <el-form-item prop="description" label="描述">
                            <el-input   v-model="form.description" placeholder="请输入" />
                        </el-form-item>
                        <el-form-item prop="remark" label="备注">
                            <el-input   v-model="form.remark"  type="textarea"  placeholder="请输入" />
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>

            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitMainDialog">确 定</el-button>
                <el-button @click="cancelMainDialog">关 闭</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import {sksDialogFormMixin} from "sks-plugin-el-erp/lib/dialog-form";
import { listOrganize, getOrganize, delOrganize, addOrganize, updateOrganize } from "/src/api/system/organize";


export default {
    name: "OrganizePageAddFromDialog",
    mixins: [
        sksDialogFormMixin,
    ],
    components: {
    },
    data() {
        return {
            defaultForm:{
                //组织
                orgName: undefined,
                //描述
                description: undefined,
                //备注
                remark: undefined,
            },
            defaultFormNotNull:{
                virtualDocumentList:[],
            },

            rules:{
                //组织
                orgName: [
                    { required: true,  message: '不能为空', trigger: "blur,change" },
                ],
                //描述
                description: [
                    { required: true,  message: '不能为空', trigger: "blur,change" },
                ],

            },
        };
    },
    methods: {
        initMainDialogInfo() {
            return {
                title: `组织`,
                //业务名称,通常用业务表名
                ownerName: `sys_organize`,
                uniqueId: `orgId`,
            }
        },
        showByOrgId({orgId,extra, dialogInfo,virtualChangeBitFlag=this.sksUtils.CHANGE_BIT_FLAG.none}){
            getOrganize(orgId).then(res=>{
                this.show({
                    extra: extra,
                    form: this.sksUtils.mergeFromObject({},res.data,{
                    }),
                    dialogInfo: dialogInfo
                })
            })
        },
        validateSuccess(){
            let  data= this.sksUtils.mergeFromObject({},this.form);

            if (!this.sksUtils.isNullOrUndefined(this.mainDialogInfo.submitCallback)){
                this.mainDialogInfo.submitCallback({submitData: data,ref: this})
                //this.showDialog=false
                return
            }

            switch(data.virtualChangeBitFlag){
                case this.sksUtils.CHANGE_BIT_FLAG.add:
                    this.allLoading=true
                    addOrganize(data).then(response => {
                        this.$modal.msgSuccess("新增成功");
                        this.closeDialog();
                        this.allLoading=false
                        if (!this.sksUtils.isNullOrUndefined(this.mainDialogInfo.submitCallbackSuccess)){
                            this.mainDialogInfo.submitCallbackSuccess({resData: response})
                        }
                    }).catch(e=>{
                        this.allLoading=false
                    })
                    break;
                case this.sksUtils.CHANGE_BIT_FLAG.modify:
                    this.allLoading=true
                    updateOrganize(data).then(response => {
                        this.$modal.msgSuccess("修改成功");
                        this.closeDialog();
                        this.allLoading=false
                        if (!this.sksUtils.isNullOrUndefined(this.mainDialogInfo.submitCallbackSuccess)){
                            this.mainDialogInfo.submitCallbackSuccess({resData: response})
                        }
                    }).catch(e=>{
                        this.allLoading=false
                    })
                    break;
                default:
                    this.$modal.msgError("未知的变更标识");
                    break;
            }
        },
    }
};
</script>

<style lange='less'>
</style>

